/* UTF8 Encoding */
/*-----------------------------------------------------------------------
|                            FILE DESCRIPTION                           |
-----------------------------------------------------------------------*/
/*----------------------------------------------------------------------
  - File name     : sharpiot.h
  - Author        : liuzhihua (liuzhihuawy@163.com)
  - Update date   : 2024.08.31
  - Brief         : sharpiot platform
  - Version       : v0.2
-----------------------------------------------------------------------*/
/*-----------------------------------------------------------------------
|                               UPDATE NOTE                             |
-----------------------------------------------------------------------*/
/**
  * Update note:
  * ------------   ---------------   ----------------------------------
  *     Date            Author                      Note
  * ------------   ---------------   ----------------------------------
  *  2024.08.28       liuzhihua                  Create file          
***/

#ifndef SHARPIOT_H
#define SHARPIOT_H

/*-----------------------------------------------------------------------
|                               INCLUDES                                |
-----------------------------------------------------------------------*/
#include <stdint.h>

/*-----------------------------------------------------------------------
|                                DEFINES                                |
-----------------------------------------------------------------------*/


class SharpIotPack
{
    public:
        typedef enum {
            TYPE_NONE = 'N',
            TYPE_BOOL = 'B',
            TYPE_INT = 'I',
            TYPE_FLOAT = 'F',
            TYPE_STRING = 'S',
            TYPE_DOUBLE = 'D',
        }SharpIot_t;
        typedef union SharpIotValueTypedef{
            bool Bool;
            int Int;
            float Float;
            const char *String;
            double Double;
        }SharpIotValue_u;

        const uint8_t *pdata;
        uint16_t size;
        uint16_t pid;
        SharpIot_t type;
        SharpIotValue_u value;
        uint32_t timestamp;

        SharpIotPack(void);
        SharpIotPack(const uint8_t *pdata, uint16_t size);
        SharpIotPack(SharpIot_t type, const uint8_t *pdata, uint16_t size);

        uint8_t *data_find_char(const uint8_t *pdata, uint16_t size, char c);

        inline uint8_t *skip_space(const uint8_t *pdata, uint16_t size, uint8_t *ptr);

        bool parse(SharpIot_t type, const uint8_t *pdata, uint16_t size);
        bool parse(const uint8_t *pdata, uint16_t size);

        uint32_t getTimestamp(void);
        uint16_t getPid(void);
        float getFloat(void);
        int getInt(void);
        bool getBool(void);
        const char *getString(void);
        double getDouble(void);

};

/*-----------------------------------------------------------------------
|                                  API                                  |
-----------------------------------------------------------------------*/
#ifdef  __cplusplus
    extern "C" {
#endif

#ifdef __cplusplus
	}
#endif
#endif
